/*
 * @Author: sjf 1758142861@qq.com
 * @Date: 2023-03-28 15:46:07
 * @LastEditors: sjf 1758142861@qq.com
 * @LastEditTime: 2023-03-30 19:30:17
 * @FilePath: /sjf/lwp/block_queue/count.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#pragma once

#include <iostream>
#include <string>
#include <cstdio>
#include <functional>
#include"forward_blockqueue.hpp"

/**
 * 基于包装器和string的实现
*/
namespace Anwtie
{
    class Task
    {
        using func_t = std::function<int(int, int)>;

    public:
        Task()
        {}
        
        Task(const int x, const int y,const char op, func_t func)
            : _x(x), _y(y),_op(op), _callback(func)
        {}
        

        std::string operator()()
        {
            int result = _callback(_x, _y);
            char buffer[1024];
            snprintf(buffer,sizeof(buffer),"%d %c %d = %d",_x,_op,_y,result);
            return buffer;
        }

    private:
        int _x;
        int _y;
        char _op;
        func_t _callback;
    };
}

/**
 * 自己test基于switch--case的实现
*/
namespace Anwite_task
{
    template <class T>
    class Task
    {
    public:
        Task(T x = 0, T y = 0, T op = 0)
            : _x(x), _y(y), _op(op)
        {
        }
        ~Task()
        {
        }
        void Runc()
        {
            int result = 0;
            switch (_op)
            {
            case '+':
                result = _x + _y;
                break;
            case '-':
                result = _x - _y;
                break;
            case '*':
                result = _x * _y;
                break;
            case '/':
                if (_y == 0)
                {
                    std::cout << "waring div zero!" << std::endl;
                    result = -1;
                }
                else
                {
                    result = _x / _y;
                }
                break;
            case '%':
                if (_y == 0)
                {
                    std::cout << "waring mod zero!" << std::endl;
                    result = -1;
                }
                else
                {
                    result = _x % _y;
                }
            default:
                std::cout << "error count!!!" << std::endl;
                break;
            }
            std::cout <<"计算机计算的任务:" << _x << _op << _y << "=" << result << std::endl;
        }

        void is_why_test()
        {
            std::cout << "计算机正在计算的任务:" << _x << _op << _y << "= ?" << std::endl; 
        }

    private:
        T _x;
        T _y;
        char _op;
    };
}